/**
  * Created by wyc on 6/9/2017.
  */
package ninenineqs

object p02 {
  def penultimate_v1[T](input:List[T]):T = {
    if (input.isEmpty) throw new NoSuchElementException
    input.init.last
  }
  def penultimate_v2[T](input:List[T]):T = {
    input match {
      case h :: _ :: Nil => h
      case _ :: tail => penultimate_v2(tail)
      case _  => throw new NoSuchElementException
    }
  }
}
